﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace UI_SATT
{
    public partial class FrmSplash : Form
    {
        BackgroundWorker bgw;
        public FrmSplash()
        {
            InitializeComponent();
            pbLoading.Maximum = 100;
            bgw = new BackgroundWorker();
            bgw.WorkerSupportsCancellation = true;
            bgw.WorkerReportsProgress = true;
            bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
            bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
            bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
            bgw.RunWorkerAsync();
        }

        private void FrmSplash_Load(object sender, EventArgs e)
        {
            pbLoading.Value = 0;
            
        }

        void bgw_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            pbLoading.Value = e.ProgressPercentage;
        }

        void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message);
            }
            else if (e.Cancelled)
            {
                this.DialogResult = DialogResult.No;
            }
            else
            {
                this.DialogResult = DialogResult.Yes;
                FrmLogin Login = new FrmLogin(this);
                Login.Show();
                this.Hide();
            }
        }

        void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                Thread.Sleep(200);
                bgw.ReportProgress(25);
                Thread.Sleep(200);
                bgw.ReportProgress(50);
                Thread.Sleep(200);
                bgw.ReportProgress(75);
                Thread.Sleep(200);
                bgw.ReportProgress(100);
                Thread.Sleep(200);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
